﻿using System;
using System.Collections.Generic;
using System.Text;
using DeviceSDK.NetTraffic.Baidu;
using BaseHelper.Base;
using DeviceSDK.NetTraffic;
using DeviceSDK.NetTraffic.Gaode;
using BaseHelper.Net;
using DeviceSDK.Radar.Haikang;
using DeviceSDK.Radar.DaHua;

namespace DeviceSDK.Radar
{
    public class RadarHelper
    {

        //监听端口

        //public delegate void TrafficDataArriveHandler(RadarDataType DType,string IP, int Jam, int CarCount, int BigCarCount, int MidCarCount, int SmallCarCount, int SpaceOccupy,int Speed);
        //public static event TrafficDataArriveHandler TrafficeDataArriveEvent = null;

        //public delegate void TrafficDataArriveRealTimeHandler(string IP, string Jam, string Speed, string QueLen);
        //public static event TrafficDataArriveRealTimeHandler TrafficeDataArriveRealTimeEvent = null;

        private static bool IsInit = false;
        private static object locker = new object();

        //public static string Api_Key_Baidu = "";
        //public static string Api_Key_Gaode = "";
        //public static string Api_TravelTime_Source = "";


        public static string Get_Error(string FirmModelIDName, int err)
        {
            if (FirmModelIDName == "HAIKANG_TCD200")
            {
                return HaiKang_TCD200.Get_Error(err);
            }
            else if (FirmModelIDName == "DAHUA_ITC235")
            {
                return DaHua_ITC235.Get_Error(err);
            }
            else
                return "设备型号不支持！";
            
        }

        public static bool IsConnected(string FirmModelIDName,string IP)
        {
            if (FirmModelIDName == "HAIKANG_TCD200")
            {
                return HaiKang_TCD200.IsConnected(IP);
            }
            else if (FirmModelIDName == "DAHUA_ITC235")
            {
                return DaHua_ITC235.IsConnected(IP);
            }
            else
                return false;
        }

        public static void Init()
        {
            lock (locker)
            {
                if (!IsInit)
                {
                    IsInit = true;
                }
            }
        }
        

        //private void TrafficeDataArriveRealTimeEventer(string IP, string Jam, string Speed, string QueLen)
        //{
        //    if (TrafficeDataArriveRealTimeEvent != null)
        //        TrafficeDataArriveRealTimeEvent(IP, Jam, Speed, QueLen);

        //}

        //设备-获取-状态
        public static int Get_Status(string FirmModelIDName, string IP)
        {
            return PingHelper.Get_Status(IP) ? 0 : 1;
        }


        public static int Set_Connect(string FirmModelIDName, string IP,string Port,string UserName,string Password)
        {

            int ret = -1;
            if (FirmModelIDName == "HAIKANG_TCD200")
            {
                return HaiKang_TCD200.Set_Connect(IP, Port,UserName, Password);
            }
            else if (FirmModelIDName == "DAHUA_ITC235")
            {
                return DaHua_ITC235.Set_Connect(IP, Port, UserName, Password);
            }
            else
            {
                ret = 1;
            }

            return ret;
        }


        public static int Set_Listen(string FirmModelIDName, string IP, string Port)
        {

            int ret = -1;
            if (FirmModelIDName == "HAIKANG_TCD200")
            {
                return HaiKang_TCD200.Set_Listen(IP,Port);
            }
            else if (FirmModelIDName == "DAHUA_ITC235")
            {
                //return DaHua_ITC235.Set_Listen(IP, Port, UserName, Password);
            }
            else
            {
                ret = 1;
            }

            return ret;
        }

 
        public static string  Get_Data(string FirmModelIDName, string CityID, string TrafficID)
        {
            string ret="";           
            if (FirmModelIDName == "BAIDUMAP_JIAOTONG")
            {
                return BaiduMap_JiaoTong.Get_Data(CityID, TrafficID);
            }
            else
            {
            }

            return ret;
        }

        //设备-关闭数据
        public static int Set_Close(string FirmModelIDName)
        {
            if (FirmModelIDName == "HAIKANG_TCD200")
            {
                HaiKang_TCD200.Set_Close();
            }
            else if (FirmModelIDName == "DAHUA_ITC235")
            {
                DaHua_ITC235.Set_Close();
            }
            else if (FirmModelIDName == "BAIDUMAP")
            {
                BaiduMap_JiaoTong.Set_Close();
            }
            return 0;
        }


    }
}
